package com.bba.manager.sku.service.impl;


import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.bba.manager.common.model.sku.Car;


import com.bba.manager.sku.mapper.CarMapper;

import com.bba.manager.sku.service.ICarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SYANDZZY
 * @since 2025-08-12
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {


    @Override
    public Car getByCarId(Long carId) {
        LambdaQueryChainWrapper<Car> wrapper = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        return wrapper.eq(Car::getId,carId).one();

    }

    /**
     * 按条件查询
     * @param car
     * @return
     */
    @Override
    public List<Car> getCar(Car car) {
        LambdaQueryWrapper<Car> wrapper = new LambdaQueryWrapper<>();

        if (car != null) {
            // 字符串判空
            if (StringUtils.isNotBlank(car.getCarType())) {
                wrapper.eq(Car::getCarType, car.getCarType());
            }
            if (StringUtils.isNotBlank(car.getColor())) {
                wrapper.eq(Car::getColor, car.getColor());
            }
            // 数值判空
            if (car.getSeriesId() != null) {
                wrapper.eq(Car::getSeriesId, car.getSeriesId());
            }
        }

        return this.list(wrapper);
    }

    @Override
    public List<Car> listByServiceId(Long serviceId) {
        LambdaQueryChainWrapper<Car> wrapper = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        return wrapper.eq(Car::getSeriesId,serviceId).list();
    }
}
